﻿@{
    ViewData["Title"] = "修改计量单位";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>修改计量单位</title>
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
        <div class="demo-login-container">

            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">车间编码</label>
                <div class="layui-input-wrap layui-input-inline">
                    <input type="text" name="MeasureCode"  lay-verify="required" placeholder="请填写车间编码" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
            </div>

            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">车间名称</label>
                <div class="layui-input-wrap layui-input-inline">
                    <input type="text" name="MeasureName"  lay-verify="required" placeholder="请填写车间名称" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
            </div>


            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">是否是主单位</label>
                <div class="layui-input-wrap layui-input-inline">
                    <input type="radio" name="PrimaryFlag" id="Y" value="Y" title="是" checked lay-verify="required" class="layui-input" lay-affix="clear">
                    <input type="radio" name="PrimaryFlag" id="N" value="N" title="否" lay-verify="required" class="layui-input" lay-affix="clear">
                </div>
            </div>

            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">是否是启用</label>
                <div class="layui-input-wrap layui-input-inline" value="${data.EnableFlag}">
                    <input type="radio" name="EnableFlag" value="Y" id="Y" title="是" checked lay-verify="required" class="layui-input" lay-affix="clear">
                    <input type="radio" name="EnableFlag" value="N" id="N" title="否" lay-verify="required" class="layui-input" lay-affix="clear">
                </div>
            </div>


            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-wrap layui-input-inline">
                    <input type="text" name="Remark"  lay-verify="required" placeholder="请填写备注" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
            </div>

            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-update">修改</button>
            </div>

        </div>
    </div>
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    <script>
        layui.use('table', function () {
            var $ = layui.$;
            var layer = layui.layer;
            var util = layui.util;
            var form = layui.form;
            var layer = layui.layer;
            var util = layui.util;

            var table = layui.table;
            var form = layui.form;
            var laydate = layui.laydate;
            var laypage = layui.laypage;
            
            function getEdit(){
                $("[name='MeasureCode']").val(parent.MeasureCode);
                $("[name='MeasureName']").val(parent.MeasureName);
                if(parent.PrimaryFlag == "Y"){
                    $("#Y").prop("checked", true);
                }
                else{
                    $("#N").prop("checked", true);
                }
                if(parent.EnableFlag == "Y"){
                    $("#Y").prop("checked", true);
                }
                else{
                    $("#N").prop("checked", true);
                }
                $("[name='Remark']").val(parent.Remark);
            }
            getEdit();
            // 事件
            //表单操作
           
                // 表单提交事件
                form.on('submit(demo-update)', function (data, index) {
                    var field = data.field; // 获取表单字段值

                    console.log(field);
                    var UpdateDto = {
                        Id: parent.Id,
                        MeasureCode: field.MeasureCode,
                        MeasureName: field.MeasureName,
                        PrimaryFlag: field.PrimaryFlag,
                        PrimaryId: field.PrimaryId,
                        EnableFlag: field.EnableFlag,
                        ChangeRate: field.ChangeRate,
                        EnableFlag: field.EnableFlag,
                        Remark: field.Remark,
                        CreateBy: parent.CreateBy,
                        CreateTime: parent.CreateTime
                    }
                    console.log(UpdateDto);

                    $.ajax({
                        url: '/MainData/UpdateUnitMeasureById',
                        type: 'Get',
                        data: UpdateDto,
                        dataType: "json",
                        success: function (res) {
                            if (res != null) {
                                alert("修改成功");
                            var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                            parent.layer.close(index);//再执行关闭
                                //跳转
                                //window.location.href = "/Main/Student/"
                            }
                            else {
                                alert("修改失败");
                            }

                        }
                    });
                    return false; // 阻止默认 form 跳转
                });
                

                
            })
       
    </script>
</body>
</html>